package com.bzy.blp.service.impl;

import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.annotation.Resource;
import com.bzy.blp.mapper.TSystemUserInfoDatMapper;
import com.bzy.blp.model.TSystemUserInfoDat;
import com.bzy.blp.model.TSystemUserInfoDatCriteria;
import com.bzy.blp.service.ISystemUserManagerService;
import com.bzy.shiro.service.IUserShiroService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class SystemUserManagerServiceImpl implements ISystemUserManagerService {

	@Resource
	private IUserShiroService userShiroService;
	@Resource
	TSystemUserInfoDatMapper tSystemUserInfoDatMapper;

	@Override
	public HashMap<String, Object> userLogin(String username, String password) throws Exception {
		userShiroService.userLogin("", username, password);

		HashMap<String, Object> resultMap = new HashMap<>();
		Set<String> roles = new HashSet<String>();
		Set<String> permissions = new HashSet<String>();
//		TblSystemUserInfoDat tblSystemUserInfoDat = queryUserByUserName(username);
//		List<TblSystemUserRoleRlt> userRoleRltList = queryRoleIdByUserId(tblSystemUserInfoDat.getUserId());
//		for (TblSystemUserRoleRlt userRoleRlt: userRoleRltList) {
//			TblSystemRoleInfoDat role = queryRoleByRoleId(userRoleRlt.getRoleId());
//			roles.add(role.getRoleName());
//			List<TblSystemRoleResourceRlt> roleResourceRltList = queryRoleResourceRltByRoleId(userRoleRlt.getRoleId());
//			for (TblSystemRoleResourceRlt roleResourceRlt : roleResourceRltList) {
//				TblSystemResourceInfoDat resource = queryResourceByResourceId(roleResourceRlt.getResourceId());
//				permissions.add(resource.getPermissionsCode() + ":" + roleResourceRlt.getPermissions());
//			}
//		}
		resultMap.put("roles", roles);
		resultMap.put("permissions", permissions);
		return resultMap;
	}

	@Override
	public TSystemUserInfoDat queryUserByUserName(String username) {
		TSystemUserInfoDat result = null;
		TSystemUserInfoDatCriteria tblSystemUserInfoDatCriteria = new TSystemUserInfoDatCriteria();
		tblSystemUserInfoDatCriteria.createCriteria().andUserNameEqualTo(username);
		List<TSystemUserInfoDat> dataList = tSystemUserInfoDatMapper.selectByExample(tblSystemUserInfoDatCriteria);
		if (dataList != null && dataList.size() > 0) {
			result = dataList.get(0);
		}
		return result;
	}
}
